package com.xuecheng.media.controller;

import com.xuecheng.api.media.TMediaApi;
import com.xuecheng.api.media.model.qo.QueryMediaModel;
import com.xuecheng.common.domain.page.PageRequestParams;
import com.xuecheng.common.domain.page.PageVO;
import com.xuecheng.common.util.SecurityUtil;
import com.xuecheng.media.service.MediaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 媒资内容控制器
 *
 * @author lily
 * @date 2021/12/15
 */
@RestController
@Slf4j
public class TMediaController implements TMediaApi {


    @Autowired
    private MediaService mediaService;

    /**
     * 查询媒资信息功能实现
     *
     * @param  pageParams 分页数据
     * @param  model      查询数据
     * @return com.xuecheng.api.media.model.dto.MediaDTO
     * @author Lily
     * @date 2021/12/15 16:07
     * @paramType [java.lang.String, java.lang.String]
     * @description
     *
     * 参数会自动封装到对象里面的参数
     */
    @PostMapping("T/media/list")
    @Override
    public PageVO queryMediaByNameOrType(PageRequestParams pageParams, QueryMediaModel model) {
        Long companyId = SecurityUtil.getCompanyId();
        PageVO pageVO = mediaService.queryMediaList(pageParams, model, companyId);
        return pageVO;
    }

    /**
     * 逻辑删除媒资信息
     *
     * @param mediaId 媒体id
     * @author Lily
     * @date 2021/12/15 19:55
     * @paramType [java.lang.Long]
     * @description
     */
    @DeleteMapping("T/media/{mediaId}")
    @Override
    public void removeMedia(@PathVariable Long mediaId) {
        Long companyId = SecurityUtil.getCompanyId();
        mediaService.removeMedia(mediaId, companyId);
    }


}
